<?php

namespace app\admin\controller;
use  app\admin\model\Admin;
use think\Session;

class Member extends Common{

    public function login(){
        $url = $this->url;
        $url = explode('refer=',$url);
        if(isset($url[1])){
            $this->assign('refer',$url[1]);
        }
        return $this->fetch();
    }

    public function reg(){
       return $this->fetch();
    }

    public function logout(){
        $params  = $this->params;
        $admin = Session::get('admin');
        $admin['handlers_log'] = $admin['admin_nickname'];
        $admin['handlers_id_log'] = $admin['id'];
        if($this->is_log){
            $this->logIns('logout',$admin,1);
        }
        Session::delete('admin');
        if(isset($params['url'])){
            $jump = '/admin/member/login?refer=' . $params['url'];
        }
        else{
            $jump = '/admin/member/login';
        }
        return_msg(1,'注销成功!',[],$jump);
    }

    public function loginSend(){
        $params =$this->params;
        $res = (new Admin())->login($params,$this->url);
        if($res['code']){
            $res['data']['handlers_log'] = $res['data']['admin_nickname'];
            $res['data']['handlers_id_log'] = $res['data']['id'];
        }
        if($this->is_log){
            $this->logIns('login',$res['data'],$res['code']);
        }
        exit( encode( $res ) );
    }


    public function regSend(){
        $params = $this->params;
        $res = (new Admin())->reg($params);
        exit( encode( $res ) );
    }

//    public function changePassword(){
//        return $this->fetch('change_password');
//    }
//
//    public function changeSub(){
//        $params =$this->params;
//        $res = (new Admin())->change($params);
//        $this->return_result($res['code'],$res['msg'],$res['data'],'member/login');
//    }


}